<?php
/**
 * Created by PhpStorm.
 * User: dronsure
 * Date: 18-3-22
 * Time: 上午11:13
 */

class SocketRolePlay extends Fend
{
    public function index(swoole_server &$server)
    {
        Fend_Func::load('FendString');
        $tmy    = array();
        $tmy['user']    = Fend_Di::factory()->get('fduser');
        $tmy['recive']  = Fend_Di::factory()->get('fdrev');
        $isjson         = FendString::isJson($tmy['recive']['rev']);
        if($isjson && !empty($tmy['recive']['rev'])){
            $tmy['recive']['rev']  = json_decode($tmy['recive']['rev'],true);
        }

        Model_Socketr_User::factory()->add(array(
            'role' => 1,
            'create_time' => time(),
            'last_login_time' => time(),
            'last_login_ip' => $tmy['user']['user_ip'],
        ));

        $tmy['recive']['rev'] = Model_Socketr_User::factory()->getList();

        foreach ($server->connections as $fd) {
            $server->push($fd, self::formatMsg($tmy));
        }

    }
}